import { _decorator, Component, EventKeyboard, Input, input, instantiate, Node, sys } from 'cc';
import * as flatted from 'flatted'
const { ccclass, property } = _decorator;

@ccclass('Test')
export class Test extends Component {

    @property(Node)
    target: Node = null!;

    start() {
        input.on(Input.EventType.KEY_DOWN, this.keyDown, this);
    }


    protected onDestroy(): void {
        input.off(Input.EventType.KEY_DOWN, this.keyDown, this);
    }

    keyDown(key: EventKeyboard) {
        let serialized = flatted.stringify(this.target);
        sys.localStorage.setItem('save', serialized)

        let native = sys.localStorage.getItem('save');
        const deserialized = flatted.parse(native);
        console.log(this.target);
        console.log(deserialized as Node);
        
    }

    update(deltaTime: number) {

    }
}


